using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Linq;

using LDAP.Entity;

namespace LDAP.BLL
{
    public class BizAttachment
    {
		public const string ENTITY_KEY = "attachment";
		
        public static long Add(Attachment entry)
        {
            Common.GetMapper(ENTITY_KEY, entry).Insert("Insert_Attachment", entry);
            return entry.Id;
        }

        public static int Update(Attachment entry)
        {
            return Common.GetMapper(ENTITY_KEY, entry).Update("Update_Attachment", entry);
        }

        public static int UpdateListStatus(string ids, long targetId)
        {
            var newIds = string.Join(",", from c in ids.Split(new[] { ' ', ',' }) select Convert.ToInt64(c));
            Hashtable ht = new Hashtable();
            ht.Add("ids", newIds);
            ht.Add("targetId", targetId);
            return Common.GetMapper(ENTITY_KEY, ht).Update("Update_AttachmentList_Status", ht);
        }

        public static Attachment GetByKey(int id)
        {
            return Common.GetMapper(ENTITY_KEY, id).QueryForObject<Attachment>("Select_Attachment", id);
        }

        public static List<Attachment> GetListByIds(string ids)
        {
            var newIds = string.Join(",", from c in ids.Split(new[] { ' ', ',' }) select Convert.ToInt64(c));
            return Common.GetMapper(ENTITY_KEY, newIds).QueryForList<Attachment>("Select_AttachmentList", newIds).ToList();
        }

        public static int Delete(string ids)
        {
            return Common.GetMapper(ENTITY_KEY, ids).Delete("Delete_Attachment", ids);
        }
    }
}

	